﻿Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class gdToolStrip
    Inherits System.Windows.Forms.ToolStripRenderer
    Private mButtonHoverBorderColor As Color = Color.FromArgb(255, 128, 192)
    Private mButtonHoverColor1 As Color = Color.FromArgb(255, 236, 255)
    Private mButtonHoverColor2 As Color = Color.FromArgb(255, 161, 255)
    Private mButtonDownBorderColor As Color = Color.FromArgb(128, 0, 128)
    Private mButtondownColor1 As Color = Color.FromArgb(255, 0, 255)
    Private mButtondownColor2 As Color = Color.FromArgb(255, 192, 255)
    Private mToolBorderColor As Color = Color.FromArgb(255, 128, 192)
    Private mToolBackColor1 As Color = Color.White
    Private mToolBackColor2 As Color = Color.FromArgb(255, 192, 255)
    Private mToolBackColor3 As Color = Color.FromArgb(255, 128, 255)
    Private mToolBackColor4 As Color = Color.FromArgb(255, 192, 255)
    Private mToolBackColor5 As Color = Color.FromArgb(250, 252, 247)
    Private mSplitColor As Color = Color.FromArgb(255, 128, 192)
    Private mGripColor As Color = Color.FromArgb(128, 0, 128)
    Private mToolMenuItemBackColor As Color = Color.White
    Private mToolMenuItemHoverColor1 As Color = Color.White
    Private mToolMenuItemHoverColor2 As Color = Color.FromArgb(255, 192, 255)
    Private mToolMenuItemHoverColor3 As Color = Color.FromArgb(255, 128, 255)
    Private mToolMenuItemHoverColor4 As Color = Color.FromArgb(255, 192, 255)
    Private mToolMenuItemHoverColor5 As Color = Color.FromArgb(250, 252, 247)
    Private mMenuLeftBackColor As Color = Color.FromArgb(150, 255, 128, 255)

    Dim DownEvent As Boolean = False
#Region "自定义属性"
    Public Property MenuLeftBackColor() As Color
        Get
            Return mMenuLeftBackColor
        End Get
        Set(ByVal value As Color)
            mMenuLeftBackColor = value
        End Set
    End Property
    Public Property ToolMenuItemHoverColor5() As Color
        Get
            Return mToolMenuItemHoverColor5
        End Get
        Set(ByVal value As Color)
            mToolMenuItemHoverColor5 = value
        End Set
    End Property
    Public Property ToolMenuItemHoverColor4() As Color
        Get
            Return mToolMenuItemHoverColor4
        End Get
        Set(ByVal value As Color)
            mToolMenuItemHoverColor4 = value
        End Set
    End Property
    Public Property ToolMenuItemHoverColor3() As Color
        Get
            Return mToolMenuItemHoverColor3
        End Get
        Set(ByVal value As Color)
            mToolMenuItemHoverColor3 = value
        End Set
    End Property
    Public Property ToolMenuItemHoverColor2() As Color
        Get
            Return mToolMenuItemHoverColor2
        End Get
        Set(ByVal value As Color)
            mToolMenuItemHoverColor2 = value
        End Set
    End Property
    Public Property ToolMenuItemHoverColor1() As Color
        Get
            Return mToolMenuItemHoverColor1
        End Get
        Set(ByVal value As Color)
            mToolMenuItemHoverColor1 = value
        End Set
    End Property
    Public Property ToolMenuItemBackColor() As Color
        Get
            Return mToolMenuItemBackColor
        End Get
        Set(ByVal value As Color)
            mToolMenuItemBackColor = value
        End Set
    End Property
    Public Property GripColor() As Color
        Get
            Return mGripColor
        End Get
        Set(ByVal value As Color)
            mGripColor = value
        End Set
    End Property
    Public Property SplitColor() As Color
        Get
            Return mSplitColor
        End Get
        Set(ByVal value As Color)
            mSplitColor = value
        End Set
    End Property
    Public Property ToolBackColor5() As Color
        Get
            Return mToolBackColor5
        End Get
        Set(ByVal value As Color)
            mToolBackColor5 = value
        End Set
    End Property
    Public Property ToolBackColor4() As Color
        Get
            Return mToolBackColor4
        End Get
        Set(ByVal value As Color)
            mToolBackColor4 = value
        End Set
    End Property
    Public Property ToolBackColor3() As Color
        Get
            Return mToolBackColor3
        End Get
        Set(ByVal value As Color)
            mToolBackColor3 = value
        End Set
    End Property
    Public Property ToolBackColor2() As Color
        Get
            Return mToolBackColor2
        End Get
        Set(ByVal value As Color)
            mToolBackColor2 = value
        End Set
    End Property
    Public Property ToolBackColor1() As Color
        Get
            Return mToolBackColor1
        End Get
        Set(ByVal value As Color)
            mToolBackColor1 = value
        End Set
    End Property
    Public Property ToolBorderColor() As Color
        Get
            Return mToolBorderColor
        End Get
        Set(ByVal value As Color)
            mToolBorderColor = value
        End Set
    End Property
    Public Property ButtondownColor2() As Color
        Get
            Return mButtondownColor2
        End Get
        Set(ByVal value As Color)
            mButtondownColor2 = value
        End Set
    End Property
    Public Property ButtondownColor1() As Color
        Get
            Return mButtondownColor1
        End Get
        Set(ByVal value As Color)
            mButtondownColor1 = value
        End Set
    End Property
    Public Property ButtonDownBorderColor() As Color
        Get
            Return mButtonDownBorderColor
        End Get
        Set(ByVal value As Color)
            mButtonDownBorderColor = value
        End Set
    End Property
    Public Property ButtonHoverColor2() As Color
        Get
            Return mButtonHoverColor2
        End Get
        Set(ByVal value As Color)
            mButtonHoverColor2 = value
        End Set
    End Property
    Public Property ButtonHoverColor1() As Color
        Get
            Return mButtonHoverColor1
        End Get
        Set(ByVal value As Color)
            mButtonHoverColor1 = value
        End Set
    End Property
    Public Property ButtonHoverBorderColor() As Color
        Get
            Return mButtonHoverBorderColor
        End Get
        Set(ByVal value As Color)
            mButtonHoverBorderColor = value
        End Set
    End Property
#End Region
    Protected Overrides Sub OnRenderButtonBackground(ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs)
        Dim ToolStrip As ToolStrip = e.ToolStrip
        Dim Item As ToolStripButton = e.Item
        Dim g As Graphics = e.Graphics
        If Not Item Is Nothing Then
            ' ToolStrip .LayoutStyle=
            Dim Bounds As Rectangle
            If ToolStrip.Orientation = Orientation.Horizontal Then
                Bounds = New Rectangle(New Point(0, 1), New Size(Item.Width - 1, Item.Height - 2))
            Else
                Bounds = New Rectangle(New Point(2, 0), New Size(Item.Width - 3, Item.Height - 1))
            End If
            Dim Brush As New LinearGradientBrush(Bounds, mButtonHoverColor1, mButtonHoverColor2, LinearGradientMode.Vertical)
            If Item.BackgroundImage IsNot Nothing Then
                g.FillRectangle(Brush, Bounds)
                g.DrawRectangle(New Pen(mButtonHoverBorderColor), Bounds)
            End If
            If Item.Selected And Item.CheckState = CheckState.Unchecked And Item.Pressed = False Then
                g.FillRectangle(Brush, Bounds)
                g.DrawRectangle(New Pen(mButtonHoverBorderColor), Bounds)
            ElseIf Item.Selected And Item.Pressed Then
                Brush = New LinearGradientBrush(Bounds, mButtondownColor1, mButtondownColor2, LinearGradientMode.Vertical)
                g.FillRectangle(Brush, Bounds)
                g.DrawRectangle(New Pen(mButtonDownBorderColor), Bounds)
            End If
            Brush.Dispose()
        End If
        MyBase.OnRenderButtonBackground(e)
    End Sub
    Protected Overrides Sub OnRenderImageMargin(ByVal e As System.Windows.Forms.ToolStripRenderEventArgs)
        'e.Graphics.FillRectangle(New SolidBrush(mToolBorderColor), e.AffectedBounds)
        MyBase.OnRenderImageMargin(e)
    End Sub

    Private Sub gdToolStrip_RenderDropDownButtonBackground(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs) Handles Me.RenderDropDownButtonBackground
        Dim ToolStrip As ToolStrip = e.ToolStrip
        Dim Item As ToolStripItem = e.Item
        Dim g As Graphics = e.Graphics
        If Not Item Is Nothing Then
            ' ToolStrip .LayoutStyle=
            Dim Bounds As Rectangle
            If ToolStrip.Orientation = Orientation.Horizontal Then
                Bounds = New Rectangle(New Point(0, 1), New Size(Item.Width - 1, Item.Height - 2))
            Else
                Bounds = New Rectangle(New Point(2, 0), New Size(Item.Width - 3, Item.Height - 1))
            End If
            Dim Brush As New LinearGradientBrush(Bounds, mButtonHoverColor1, mButtonHoverColor2, LinearGradientMode.Vertical)
            If Item.BackgroundImage IsNot Nothing Then
                '  g.FillRectangle(Brush, Bounds)
                g.DrawRectangle(New Pen(mButtonHoverBorderColor), Bounds)
            End If
            If Item.Selected Then
                g.FillRectangle(Brush, Bounds)
                g.DrawRectangle(New Pen(mButtonHoverBorderColor), Bounds)
            ElseIf Item.Pressed Then
                ' MsgBox("down")
                Brush = New LinearGradientBrush(Bounds, mButtondownColor1, mButtondownColor2, LinearGradientMode.Vertical)
                g.FillRectangle(Brush, Bounds)
                g.DrawRectangle(New Pen(mButtonDownBorderColor), Bounds)
            End If
            Brush.Dispose()
        End If
    End Sub

    Private Sub gdToolStrip_RenderGrip(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripGripRenderEventArgs) Handles Me.RenderGrip
        If e.GripStyle = ToolStripGripStyle.Hidden Then Return
        Dim g As Graphics = e.Graphics
        Dim GripStyle As ToolStripGripDisplayStyle = e.GripDisplayStyle
        Dim Bounds As Rectangle = e.GripBounds
        Dim Count As Integer, PointWidth As Integer = Bounds.Width / 2
        Dim TmpRect As Rectangle, dBrush As New SolidBrush(mGripColor)
        If GripStyle = ToolStripGripDisplayStyle.Horizontal Then
            PointWidth = Bounds.Height / 2
            Count = Bounds.Width \ PointWidth
            For i = 0 To Count - 1
                If i Mod 2 <> 0 Then
                    TmpRect = New Rectangle(i * PointWidth, Bounds.Top, PointWidth, PointWidth)
                    g.FillRectangle(dBrush, TmpRect)
                End If
            Next
        Else
            PointWidth = Bounds.Width / 2
            Count = Bounds.Height \ PointWidth
            For i = 0 To Count - 1
                If i Mod 2 <> 0 Then
                    TmpRect = New Rectangle(Bounds.Left, i * PointWidth, PointWidth, PointWidth)
                    g.FillRectangle(dBrush, TmpRect)
                End If
            Next
        End If
    End Sub

    Private Sub gdToolStrip_RenderLabelBackground(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs) Handles Me.RenderLabelBackground
        ' e.Graphics.FillRectangle(New SolidBrush(Color.Blue), New Rectangle(0, 0, e.Item.Width, e.Item.Height))
        Dim ToolStrip As ToolStrip = e.ToolStrip
        Dim Item As ToolStripItem = e.Item
        Dim g As Graphics = e.Graphics
        If Not Item Is Nothing Then
            ' ToolStrip .LayoutStyle=

            Dim Bounds As Rectangle
            If ToolStrip.Orientation = Orientation.Horizontal Then
                Bounds = New Rectangle(New Point(0, 1), New Size(Item.Width - 1, Item.Height - 2))
            Else
                Bounds = New Rectangle(New Point(2, 0), New Size(Item.Width - 3, Item.Height - 1))
            End If
            Dim Brush As New LinearGradientBrush(Bounds, mButtonHoverColor1, mButtonHoverColor2, LinearGradientMode.Vertical)
            If Item.BackgroundImage IsNot Nothing Then
                g.FillRectangle(Brush, Bounds)
                g.DrawRectangle(New Pen(mButtonHoverBorderColor), Bounds)
            End If
            If Item.Pressed = True Then

                Brush = New LinearGradientBrush(Bounds, mButtondownColor1, mButtondownColor2, LinearGradientMode.Vertical)
                g.FillRectangle(Brush, Bounds)
                g.DrawRectangle(New Pen(mButtonDownBorderColor), Bounds)
            ElseIf Item.Selected Then
                g.FillRectangle(Brush, Bounds)
                g.DrawRectangle(New Pen(mButtonHoverBorderColor), Bounds)
            End If
            Brush.Dispose()
        End If
    End Sub

    Private Sub gdToolStrip_RenderMenuItemBackground(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs) Handles Me.RenderMenuItemBackground
        Dim g As Graphics = e.Graphics
        Dim Item As ToolStripItem = e.Item
        Dim LeftRect As New Rectangle(1, 0, 35, Item.Height)
        If Item.Selected = False Then
            g.FillRectangle(New SolidBrush(mToolMenuItemBackColor), New Rectangle(0, 0, Item.Width, Item.Height))
            g.FillRectangle(New SolidBrush(mMenuLeftBackColor), LeftRect)
        Else
            Dim ColorB As New ColorBlend
            Dim Bounds As Rectangle = New Rectangle(New Point(1, 0), New Size(Item.Width - 2, Item.Height - 1))
            Dim Dbrush As New LinearGradientBrush(Bounds, mToolMenuItemHoverColor1, mToolMenuItemHoverColor2, LinearGradientMode.Vertical)

            ColorB.Colors = New Color() {mToolMenuItemHoverColor1, mToolMenuItemHoverColor2, mToolMenuItemHoverColor3, mToolMenuItemHoverColor4, mToolMenuItemHoverColor5}
            ColorB.Positions = New Single() {0 / 4.0F, 1 / 4.0F, 2 / 4.0F, 3 / 4.0F, 4 / 4.0F}
            Dbrush.InterpolationColors = ColorB
            g.FillRectangle(New SolidBrush(mMenuLeftBackColor), LeftRect)
            g.FillRectangle(Dbrush, Bounds)
            g.DrawRectangle(New Pen(mButtonHoverBorderColor), Bounds)
        End If
    End Sub

    Private Sub gdToolStrip_RenderOverflowButtonBackground(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs) Handles Me.RenderOverflowButtonBackground
        Dim Item As ToolStripItem = e.Item
        Dim g As Graphics = e.Graphics
        Dim Bounds As Rectangle = New Rectangle(New Point(0, 1), New Size(Item.Width - 2, Item.Height - 2))
        Dim Dbrush As LinearGradientBrush
        If e.ToolStrip.Orientation = Orientation.Horizontal Then
            Dbrush = New LinearGradientBrush(Bounds, mButtonHoverColor1, mButtonHoverColor2, LinearGradientMode.Vertical)
        Else
            Dbrush = New LinearGradientBrush(Bounds, mButtonHoverColor1, mButtonHoverColor2, LinearGradientMode.Horizontal)
        End If

        If Item.Selected = True And Item.Pressed = False Then
            g.FillRectangle(Dbrush, Bounds)
            g.DrawRectangle(New Pen(mButtonHoverBorderColor), Bounds)
        ElseIf Item.Selected And Item.Pressed Then
            If e.ToolStrip.Orientation = Orientation.Horizontal Then
                Dbrush = New LinearGradientBrush(Bounds, mButtondownColor1, mButtondownColor2, LinearGradientMode.Vertical)
            Else
                Dbrush = New LinearGradientBrush(Bounds, mButtondownColor1, mButtondownColor2, LinearGradientMode.Horizontal)
            End If
            g.FillRectangle(Dbrush, Bounds)
            g.DrawRectangle(New Pen(mButtonDownBorderColor), Bounds)
        End If
        g.DrawLine(New Pen(Color.Black), Bounds.Left + 4, Convert.ToInt32(Bounds.Height / 2) - 1, Bounds.Width - 4, Convert.ToInt32(Bounds.Height / 2) - 1)
        DrawDownLogo(g, New Rectangle(Bounds.Left, Bounds.Top + Bounds.Height / 2, Bounds.Width, Bounds.Height / 2))
    End Sub

    Private Sub gdToolStrip_RenderSeparator(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripSeparatorRenderEventArgs) Handles Me.RenderSeparator
        Dim g As Graphics = e.Graphics
        Dim DrawRect As Rectangle = New Rectangle(Point.Empty, New Size(e.Item.Width + 1, e.Item.Height))
        If e.ToolStrip.IsDropDown Then
            DrawRect = New Rectangle(0, 0, e.Item.Width, e.Item.Height)
            ' g.FillRectangle(New SolidBrush(mToolMenuItemBackColor), New Rectangle(1, 0, e.Item.Width, e.Item.Height))
            g.DrawLine(New Pen(mSplitColor), 35, 0, DrawRect.Right - 2, 0)

        Else
            If e.ToolStrip.Orientation = Orientation.Vertical Then
                g.DrawLine(New Pen(mSplitColor), New Point(4, DrawRect.Top + DrawRect.Height / 2), New Point(e.Item.Width - 4, DrawRect.Top + DrawRect.Height / 2))
            Else
                g.DrawLine(New Pen(mSplitColor), New Point(DrawRect.Left + DrawRect.Width / 2, 4), New Point(DrawRect.Left + DrawRect.Width / 2, DrawRect.Height - 4))
            End If
        End If
    End Sub

    Private Sub gdToolStrip_RenderSplitButtonBackground(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs) Handles Me.RenderSplitButtonBackground
        Dim g As Graphics = e.Graphics
        Dim ToolStrip As ToolStrip = e.ToolStrip
        Dim Item As ToolStripSplitButton = e.Item
        If Item IsNot Nothing Then
            Dim DrawBrush As LinearGradientBrush
            Dim mWidth As Integer
            Dim Bounds As Rectangle
            If ToolStrip.Orientation = Orientation.Horizontal Then
                Bounds = New Rectangle(0, 1, e.Item.Width - 1, e.Item.Height - 2)
                mWidth = 10
            ElseIf ToolStrip.Orientation = Orientation.Vertical Then
                Bounds = New Rectangle(2, 0, e.Item.Width - 3, e.Item.Height - 1)
                mWidth = 14
            End If
            Dim MRect As Rectangle = New Rectangle(Bounds.Right - mWidth, Bounds.Top, mWidth, Bounds.Height)
            g.SmoothingMode = SmoothingMode.HighQuality
            If (Item.BackgroundImage IsNot Nothing) And Item.ButtonSelected = False And Item.Pressed = False Then
                DrawBackGroundImage(g, Item.BackgroundImage, Item.BackgroundImageLayout, Bounds)
                DrawDownLogo(g, MRect)
            ElseIf Item.BackgroundImage Is Nothing And Item.ButtonPressed = False And Item.Pressed = False And Item.Selected = False Then
                DrawDownLogo(g, MRect)
            ElseIf Item.Selected And Item.ButtonPressed = False Then
                DrawBrush = New LinearGradientBrush(Bounds, mButtonHoverColor1, mButtonHoverColor2, LinearGradientMode.Vertical)
                g.FillRectangle(DrawBrush, Bounds)
                g.DrawRectangle(New Pen(mButtonHoverBorderColor), Bounds)
                g.DrawLine(New Pen(mButtonHoverBorderColor), MRect.Left, MRect.Top, MRect.Left, MRect.Bottom)
                DrawDownLogo(g, MRect)
            ElseIf Item.ButtonPressed = True Then
                DrawBrush = New LinearGradientBrush(Bounds, mButtondownColor1, mButtondownColor2, LinearGradientMode.Vertical)
                Dim MBrush As New LinearGradientBrush(Bounds, mButtonHoverColor1, mButtonHoverColor2, LinearGradientMode.Vertical)
                g.FillRectangle(MBrush, MRect)
                g.DrawRectangle(New Pen(mButtonHoverBorderColor), MRect)
                g.FillRectangle(DrawBrush, New Rectangle(Bounds.Location, New Size(Bounds.Width - mWidth, Bounds.Height)))
                g.DrawRectangle(New Pen(mButtonDownBorderColor), New Rectangle(Bounds.Location, New Size(Bounds.Width - mWidth, Bounds.Height)))
                DrawDownLogo(g, MRect)
            ElseIf Item.Pressed Then
                DrawBrush = New LinearGradientBrush(Bounds, mButtondownColor1, mButtondownColor2, LinearGradientMode.Vertical)
                Dim MBrush As New LinearGradientBrush(Bounds, mButtonHoverColor1, mButtonHoverColor2, LinearGradientMode.Vertical)
                g.FillRectangle(DrawBrush, MRect)
                g.DrawRectangle(New Pen(mButtonDownBorderColor), MRect)
                g.FillRectangle(MBrush, New Rectangle(Bounds.Location, New Size(Bounds.Width - mWidth, Bounds.Height)))
                g.DrawRectangle(New Pen(mButtonHoverBorderColor), New Rectangle(Bounds.Location, New Size(Bounds.Width - mWidth, Bounds.Height)))
                DrawDownLogo(g, MRect)
            End If
        End If
    End Sub
    Private Sub DrawDownLogo(ByVal g As Graphics, ByVal Bounds As Rectangle)
        Dim LogoPath As GraphicsPath = New GraphicsPath(FillMode.Alternate)
        Dim R As Integer = 6
        Dim Rh As Integer = Math.Sin(60.0F) * R
        With LogoPath
            .AddLine(New Point(Bounds.Left + Convert.ToInt32((Bounds.Width - R) / 2), Bounds.Top + Convert.ToInt32((Bounds.Height - R) / 2)), New Point(Bounds.Right - Convert.ToInt32((Bounds.Width - R) / 2), Bounds.Top + Convert.ToInt32((Bounds.Height - R) / 2)))
            .AddLine(New Point(Bounds.Right - Convert.ToInt32((Bounds.Width - R) / 2), Bounds.Top + Convert.ToInt32((Bounds.Height - R) / 2)), New Point(Bounds.Left + Bounds.Width / 2, Bounds.Bottom - Convert.ToInt32((Bounds.Height - R) / 2) - 2))
            .AddLine(New Point(Bounds.Left + Bounds.Width / 2, Bounds.Bottom - Convert.ToInt32((Bounds.Height - R) / 2) - 2), New Point(Bounds.Left + Convert.ToInt32((Bounds.Width - R) / 2), Bounds.Top + Convert.ToInt32((Bounds.Height - R) / 2)))
        End With
        g.FillPath(New SolidBrush(Color.Black), LogoPath)
        LogoPath.Dispose()
    End Sub
    Private Sub DrawBackGroundImage(ByVal g As Graphics, ByVal Img As Bitmap, ByVal LayOut As ImageLayout, ByVal Bounds As Rectangle)
        Select Case LayOut
            Case ImageLayout.None
                g.DrawImage(Img, 0, 0, Img.Width, Img.Height)
            Case ImageLayout.Center
                g.DrawImage(Img, Convert.ToInt32((Bounds.Width - Img.Width) / 2), Convert.ToInt32((Bounds.Height - Img.Height) / 2), Img.Width, Img.Height)
            Case ImageLayout.Stretch
                g.DrawImage(Img, Bounds, New Rectangle(0, 0, Img.Width, Img.Height), GraphicsUnit.Pixel)
            Case ImageLayout.Tile
                Dim TextBrush As New TextureBrush(Img)
                g.FillRectangle(TextBrush, Bounds)
            Case ImageLayout.Zoom
                If Img.Width <= Bounds.Width And Img.Height <= Bounds.Height Then
                    Dim tmpWidth As Integer, tmpHeight As Integer
                    If Img.Width < Img.Height Then
                        tmpHeight = Bounds.Height
                        tmpWidth = Bounds.Width * (Bounds.Height / Img.Height)
                    ElseIf Img.Width > Img.Height Then
                        tmpWidth = Bounds.Width
                        tmpHeight = Bounds.Height * (Bounds.Width / Bounds.Width)
                    End If
                    g.DrawImage(Img, New Rectangle(Convert.ToInt32((Bounds.Width - tmpWidth) / 2), Convert.ToInt32((Bounds.Height - tmpHeight) / 2), tmpWidth, tmpHeight), New Rectangle(0, 0, Img.Width, Img.Height), GraphicsUnit.Pixel)
                Else
                    g.DrawImage(Img, 0, 0, Img.Width, Img.Height)
                End If
        End Select
    End Sub
    Private Sub gdToolStrip_RenderToolStripBackground(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripRenderEventArgs) Handles Me.RenderToolStripBackground
        Dim Bounds As Rectangle = e.AffectedBounds
        Dim DrawBrush As LinearGradientBrush = Nothing
        Dim g As Graphics = e.Graphics
        Dim ToolStrip As ToolStrip = e.ToolStrip
        Dim ColorB As New ColorBlend
        With ToolStrip
            If .IsDropDown = False Then
                If .Orientation = Orientation.Horizontal Then
                    DrawBrush = New LinearGradientBrush(Bounds, mToolBackColor1, mToolBackColor2, LinearGradientMode.Vertical)
                ElseIf .Orientation = Orientation.Vertical Then
                    DrawBrush = New LinearGradientBrush(Bounds, mToolBackColor1, mToolBackColor2, LinearGradientMode.Horizontal)
                End If
                ColorB.Colors = New Color() {mToolBackColor1, mToolBackColor2, mToolBackColor3, mToolBackColor4, mToolBackColor5}
                ColorB.Positions = New Single() {0 / 4.0F, 1 / 4.0F, 2 / 4.0F, 3 / 4.0F, 4 / 4.0F}
                If DrawBrush IsNot Nothing Then
                    DrawBrush.InterpolationColors = ColorB
                    g.FillRectangle(DrawBrush, Bounds)
                End If
            Else

                g.FillRectangle(New SolidBrush(mToolMenuItemBackColor), Bounds)
                Dim LeftRect As New Rectangle(0, 0, 36, Bounds.Height)
                g.FillRectangle(New SolidBrush(mMenuLeftBackColor), LeftRect)
            End If
            g.DrawRectangle(New Pen(mToolBorderColor), New Rectangle(Bounds.Location, New Size(Bounds.Width - 1, Bounds.Height - 1)))
        End With
    End Sub

    Private Sub gdToolStrip_RenderToolStripBorder(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripRenderEventArgs) Handles Me.RenderToolStripBorder
        Dim Border As Rectangle = e.AffectedBounds
        e.Graphics.DrawRectangle(New Pen(mToolBorderColor), New Rectangle(Border.Location, New Size(Border.Width - 1, Border.Height - 1)))

    End Sub

    Private Sub gdToolStrip_RenderToolStripStatusLabelBackground(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs) Handles Me.RenderToolStripStatusLabelBackground
        Dim ToolStrip As ToolStrip = e.ToolStrip
        Dim Item As ToolStripButton = e.Item
        Dim g As Graphics = e.Graphics
        If Not Item Is Nothing Then
            ' ToolStrip .LayoutStyle=
            Dim Bounds As Rectangle
            If ToolStrip.Orientation = Orientation.Horizontal Then
                Bounds = New Rectangle(New Point(0, 1), New Size(Item.Width - 1, Item.Height - 2))
            Else
                Bounds = New Rectangle(New Point(2, 0), New Size(Item.Width - 3, Item.Height - 1))
            End If
            Dim Brush As New LinearGradientBrush(Bounds, mButtonHoverColor1, mButtonHoverColor2, LinearGradientMode.Vertical)
            If Item.BackgroundImage IsNot Nothing Then
                g.FillRectangle(Brush, Bounds)
                g.DrawRectangle(New Pen(mButtonHoverBorderColor), Bounds)
            End If
            If Item.Selected And Item.Selected And Item.Pressed = False Then
                g.FillRectangle(Brush, Bounds)
                g.DrawRectangle(New Pen(mButtonHoverBorderColor), Bounds)
            ElseIf Item.Selected And Item.Pressed Then
                Brush = New LinearGradientBrush(Bounds, mButtondownColor1, mButtondownColor2, LinearGradientMode.Vertical)
                g.FillRectangle(Brush, Bounds)
                g.DrawRectangle(New Pen(mButtonDownBorderColor), Bounds)
            End If
            Brush.Dispose()
        End If
    End Sub
End Class
